﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WindowsFormsView;
using WindowsFormsModel.BusinessObjects;

namespace WindowsFormsPresenter.RestaurantMenuNorm
{
    public class RestaurantMenuNormPresenter : Presenter<IRestaurantMenuNormView>
    {
        public RestaurantMenuNormPresenter(IRestaurantMenuNormView view)
            : base(view)
        {
        }

        public void Display(string menuNormId)
        {
            if (menuNormId == null) return;

            var restaurantMenuNorm = Model.GetRestaurantMenuNorm(menuNormId);

            View.MenuNormID = restaurantMenuNorm.MenuNormID;
            View.MenuNormCode = restaurantMenuNorm.MenuNormCode;
            View.MenuNormName = restaurantMenuNorm.MenuNormName;
            View.RestaurantID = restaurantMenuNorm.RestaurantID;
            View.Description = restaurantMenuNorm.Description;
            View.MenuID = restaurantMenuNorm.MenuID;
            View.RestaurantMenuNormDetails = restaurantMenuNorm.RestaurantMenuNormDetails;
        }

        public int Save()
        {
            var restaurantMenuNorm = new RestaurantMenuNormModel
            {
                MenuNormID = View.MenuNormID,
                MenuNormCode = View.MenuNormCode,
                MenuNormName = View.MenuNormName,
                RestaurantID = View.RestaurantID,
                Description = View.Description,
                MenuID = View.MenuID,
                RestaurantMenuNormDetails = View.RestaurantMenuNormDetails
            };

            if (View.MenuNormID == null)
                return Model.AddRestaurantMenuNorm(restaurantMenuNorm);
            else
                return Model.UpdateRestaurantMenuNorm(restaurantMenuNorm);
        }

        public int Delete(string menuNormId)
        {
            return Model.DeleteRestaurantMenuNorm(menuNormId);
        }
    }
}
